home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Programming / amigatalk / system / ParallelDevice.st < prev    next >
Encoding:
Text File  |  2001-03-06  |  4.4 KB  |  135 lines

  1. " ----------------------------------------------------------------------"
  2. " ParallelDevice Class is derived from abstract Device Class.           "
  3.  
  4. "  WARNING:  You should know what you're doing to the Amiga OS before   "
  5. "            messing with this Class, or any other System Class!        " 
  6.  
  7. " This class is a Singleton Class.  In the future, this class will be   "
  8. " modified to allow more than one Parallel port to be open at a time    "
  9. " (for those of us fortunate enough to have more than one Parallel Port."
  10. " Methods will have to be added for specifying the parallel device name."
  11.  
  12. " NOTES
  13.  
  14.   parallelFlags can have any or all of the following values:
  15.  
  16.     2r00000010 PARF_EOFMODE  - check I/O against the TermChars array.
  17.     2r00000100 PARF_ACKMODE  - use ACK handshaking.
  18.     2r00001000 PARF_FASTMODE - Send out data as long as BUSY is low. 
  19.     2r00010000 PARF_SLOWMODE - For transfers to slow printers.
  20.     2r00100000 PARF_SHARED   - Allow sharing of the parallel device.    "
  21.  
  22. "   The parallel.device will NOT open without the PARF_SHARED flag, so  "
  23. "   AmigaTalk will ensure that PARF_SHARED is present & supply it if not"
  24.  
  25. "  For the status method, the returned status has the following meaning:"
  26.  
  27. "   BIT:  ACTIVE:  FUNCTION:"
  28.  
  29. "    0      HIGH   Printer Busy toggle (offline)."
  30. "    1      HIGH   Paper out."
  31. "    2      HIGH   Printer Select."
  32. "    3      ----   Read = 0, Write = 1"
  33. "   4-7     ----   Reserved."
  34.  
  35. " ----------------------------------------------------------------------"
  36.  
  37. Class ParallelDevice :Device ! uniqueInstance !
  38. [
  39.    status
  40.       ^ <primitive 224 3>
  41. |
  42.    resetPort
  43.       ^ <primitive 224 4>
  44. |                  
  45.    flushPort
  46.       ^ <primitive 224 5>
  47. |                  
  48.    stopPort
  49.       ^ <primitive 224 6>
  50. |                  
  51.    startPort
  52.       ^ <primitive 224 7>
  53. |                  
  54.    setTerminatorsTo: aString
  55.       "Only the first 4 characters of the string are used."
  56.       "They have to be in descending ASCII sequence."
  57.       ^ <primitive 224 11 aString>
  58. |                  
  59.    setPortDirectionAtomic: rwFlag
  60.       " Not needed for reading & writing to the Parallel Port."
  61.       ^ <primitive 224 12 rwFlag>
  62. |                  
  63.    sendPortControlBits: newBits
  64.       " Only the 3 least-significant bits will be written to the hardware.
  65.         This is to prevent your code from interfering with the Serial
  66.         device.
  67.       "
  68.       ^ <primitive 224 13 newBits>
  69. |                  
  70.    readControlBitsMaskedBy: ctrlMask
  71.       " Only the 3 least-significant bits have any meaning 
  72.         for the Parallel Port.  Use ctrlMask of seven (7).
  73.       "
  74.       ^ <primitive 224 14 ctrlMask>
  75. |
  76.    testToggleCtrlBits: loopCount
  77.      "Use this method only for verifying operation of control bits"
  78.      "using test equipment of some kind on your hardware!"
  79.      "loopCount of 1 is around 60 milli-Seconds so do NOT use values"
  80.      "greater than 60,000 (over 1 hour)"
  81.      <primitive 224 15 loopCount>
  82. |
  83.    testToggleDataBits: loopCount
  84.      "Use this method only for verifying operation of data bits"
  85.      "using test equipment of some kind on your hardware!"
  86.      "loopCount of 1 is around 60 milli-Seconds so do NOT use values"
  87.      "greater than 60,000 (over 1 hour)"
  88.      <primitive 224 16 loopCount>
  89. |
  90.    privateOpen: parallelFlags ! check !
  91.  
  92.    "open: devName unit: unitNum withFlags: parallelFlags -- for later."
  93.  
  94.       check <- <primitive 224 1 parallelFlags>.
  95.  
  96.       (check ~= 0)
  97.          ifTrue: [ 'Error opening parallel.device:' print.
  98.                    <primitive 224 2 check> print.
  99.                    ^ nil
  100.                  ].
  101.       ^ self
  102. |
  103.    close
  104.       <primitive 224 0>
  105. |
  106.    new 
  107.       'Cannot use new method on Parallel class!' print.
  108.       ^ nil
  109. |
  110.    privateSetup: parallelFlags ! chk !
  111.       (uniqueInstance isNil)
  112.          ifTrue: [ chk <- (self privateOpen: parallelFlags).
  113.  
  114.                    (chk ~= nil)
  115.                       ifTrue: [uniqueInstance <- self]  "<- chk??"
  116.                  ].
  117.  
  118.       (chk ~= nil)
  119.          ifTrue:  [^ self]  "^ uniqueInstance??"
  120.          ifFalse: [^ nil ]
  121. |
  122.    new: parallelFlags
  123.       ^ (self privateSetup: parallelFlags)
  124. |
  125.    readThisMany: numChars
  126.       ^ <primitive 224 9 numChars>
  127. |
  128.    writeToPort: aString thisLong: numChars ! check !
  129.       "your device must handshake with the Amiga.  Most printers do."
  130.       check <- <primitive 224 10 numChars aString>.
  131.       
  132.       (check ~= numChars)
  133.          ifTrue: [ 'Parallel Port write error!' print]
  134. ]
  135.